package com.ruoyi.neo.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.neo.domain.Part;
import com.ruoyi.neo.domain.PartView;
import com.ruoyi.neo.service.IPartViewService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;

import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 零件三视图Controller
 * 
 * @author ruoyi
 * @date 2025-03-16
 */
@RestController
@RequestMapping("/neo4j/view")
public class PartViewController extends BaseController
{
    @Autowired
    private IPartViewService partViewService;

    /**
     * 查询零件三视图列表
     */
//    @PreAuthorize("@ss.hasPermi('neo4j:view:list')")
//    @GetMapping("/list")
//    public TableDataInfo list(PartView partView)
//    {
//        startPage();
//        List<PartView> list = partViewService.selectPartViewList(partView);
//        return getDataTable(list);
//
//    }
    @GetMapping("/list")
    public AjaxResult getPartCategoryGraph() {
        List<PartView> partViews = partViewService.selectPartViewList(new PartView());
        return success(partViews);
    }
//    零件所有编号
    @PreAuthorize("@ss.hasPermi('neo4j:view:partNumbers')")
    @GetMapping("/partNumbers")
    public AjaxResult partNumberList()
    {
        return success(partViewService.selectAllPartNumber());
    }

    /**
     * 导出零件三视图列表
     */
    @PreAuthorize("@ss.hasPermi('neo4j:view:export')")
    @Log(title = "零件三视图", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PartView partView)
    {
        List<PartView> list = partViewService.selectPartViewList(partView);
        ExcelUtil<PartView> util = new ExcelUtil<PartView>(PartView.class);
        util.exportExcel(response, list, "零件三视图数据");
    }

    /**
     * 获取零件三视图详细信息
     */
    @PreAuthorize("@ss.hasPermi('neo4j:view:query')")
    @GetMapping(value = "/{viewId}")
    public AjaxResult getInfo(@PathVariable("viewId") Long viewId)
    {
        return success(partViewService.selectPartViewByViewId(viewId));
    }

    /**
     * 新增零件三视图
     */
    @PreAuthorize("@ss.hasPermi('neo4j:view:add')")
    @Log(title = "零件三视图", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PartView partView)
    {
        return toAjax(partViewService.insertPartView(partView));
    }

    /**
     * 修改零件三视图
     */
    @PreAuthorize("@ss.hasPermi('neo4j:view:edit')")
    @Log(title = "零件三视图", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PartView partView)
    {
        return toAjax(partViewService.updatePartView(partView));
    }

    /**
     * 删除零件三视图
     */
//    @PreAuthorize("@ss.hasPermi('neo4j:view:remove')")
//    @Log(title = "零件三视图", businessType = BusinessType.DELETE)
//	@DeleteMapping("/{viewIds}")
//    public AjaxResult remove(@PathVariable Long[] viewIds)
//    {
//        return toAjax(partViewService.deletePartViewByViewIds(viewIds));
//    }
    @PreAuthorize("@ss.hasPermi('neo4j:view:remove')")
    @Log(title = "零件三视图", businessType = BusinessType.DELETE)
    @DeleteMapping("/{viewNumber}")
    public AjaxResult remove(@PathVariable String viewNumber)
    {
        return toAjax(partViewService.deletePartViewByViewNumber(viewNumber));
    }

}
